const { cloneDeep, isObject, isArray, isString } = require('lodash')
const { ObjectID } = require('mongodb')

function convertToObjectId (origin) {
  let target = cloneDeep(origin)
  if (isObject(target)) {
    target._id = ObjectID(target._id)
  }
  if (isString(target)) {
    target = ObjectID(target)
  }
  if (isArray(target)) {
    target = target.map(e => ObjectID(e))
  }
  return target
}

module.exports = {
  convertToObjectId
}
